***** STATA version 16.1
* Plots support towards major political parties from 2013 to 2019
* original data source: HKU Public Opinion Programme
* raw data available at https://www.hkupop.hku.hk/chinese/popexpress/pgrating/topten1.html
* 
* 
* figure: D2

clear all
set more off

***** additional packages required to run the code, uncomment to install
// ssc install blindschemes, replace

cd "/path/to/current/directory/"

set scheme plotplain
******** 
*** read data
use party_rating.dta, clear

*** create folders if not already existed
capture mkdir "figures"

*** dates of two elections
display date("20160904","YMD")
* Sep 2016 general election: 20701
display date("20180311","YMD")
* Mar 2018 by-election: 21254

***** plot figure
* figure D2
local mo_color ""229 178 0""
local ra_color ""229 178 0 *2""
local es_color ebblue

twoway (connected rating date if party=="DAB", legend(label(1 "DAB")) color(`es_color') msymbol(O) lpattern(solid)) || ///
	(connected rating date if party=="LP", legend(label(2 "LP")) color(`es_color') msymbol(o) lpattern(shortdash)) || ///
	(connected rating date if party=="CP", legend(label(3 "CP")) color(`mo_color') msymbol(S) lpattern(solid)) || ///
	(connected rating date if party=="DP", legend(label(4 "DP")) color(`mo_color') msymbol(s) lpattern(shortdash)) || ///
	(connected rating date if party=="LSD", legend(label(5 "LSD")) color(`ra_color') msymbol(D) lpattern(solid)) || ///
	(connected rating date if party=="PP", legend(label(6 "PP")) color(`ra_color') msymbol(d) lpattern(shortdash)) || ///
	(rcap rating_ll rating_ul date if party=="DAB", color(`es_color')) || ///
	(rcap rating_ll rating_ul date if party=="LP", color(`es_color')) || ///
	(rcap rating_ll rating_ul date if party=="CP", color(`mo_color')) || ///
	(rcap rating_ll rating_ul date if party=="DP", color(`mo_color')) || ///
	(rcap rating_ll rating_ul date if party=="LSD", color(`ra_color')) || ///
	(rcap rating_ll rating_ul date if party=="PP", color(`ra_color')) ///
	, xline(20701, lcolor(red)) xline(21254, lcolor(red)) ///
	ylabel(0(10)60)	legend(order(- "Establishment" 1 2 - - "Moderate Democrat" 3 4 - - "Radical Democrat" 5 6)) ///
	ytitle("Rating") xtitle("Date")
graph export "figures/figure D2.png", replace
